package com.cuit.blogsystem.service.Impl;

import com.cuit.blogsystem.DTO.TextPageQueryDTO;
import com.cuit.blogsystem.DTO.TypePageQueryDTO;
import com.cuit.blogsystem.Result.PageResult;
import com.cuit.blogsystem.VO.TextVO;
import com.cuit.blogsystem.VO.TypeVO;
import com.cuit.blogsystem.mapper.TextMapper;
import com.cuit.blogsystem.service.TextService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TextServiceImpl implements TextService {
    @Autowired
    private TextMapper textMapper;
    @Override
    public PageResult pageQueery(TextPageQueryDTO textPageQueryDTO) {
        PageHelper.startPage(textPageQueryDTO.getPage(),textPageQueryDTO.getPageSize());
        Page<TextVO> textPage = textMapper.pageQuery(textPageQueryDTO);
        return new PageResult(textPage.getTotal(), textPage.getResult());
    }

    /**
     * 单篇文章查询
     * @param id
     */
    @Override
    public TextVO listText(Long id) {
        return textMapper.findById(id);
    }

    @Override
    public List<String> pageQueeryType() {
        return textMapper.listType();
    }

    @Override
    public PageResult listType(TypePageQueryDTO typePageQueryDTO) {
        PageHelper.startPage(typePageQueryDTO.getPage(),typePageQueryDTO.getPageSize());
        Page<TypeVO> typePage = textMapper.typePageQuery(typePageQueryDTO);
        return new PageResult(typePage.getTotal(), typePage.getResult());
    }
}
